<?php

class TricksController extends AppController{
    
    
    
    public function admin_edit(){
        $tricksTypes = $this->Trick->TricksTypesSpin->TricksType->find('all', array(
            'order' => array('TricksType.name', 'TricksType.multiple'),
        ));
                
        $this->set('tricksTypes',$tricksTypes);
        
        
        $sports = $this->Trick->Sport->find('all', array(
            'recursive' => -1,
            'order' => array('name')
        ));
        
        $this->set('sports', $sports);
        
        $tricks = $this->Trick->find('all', array(
           'recursive' => -1,
        ));
        
        $tricksKeys = array();
        foreach ($tricks as $trick){
            $tricksKeys[$trick['Trick']['sports_id'].'-'.$trick['Trick']['tricks_types_spins_id']] = $trick['Trick']['id'];
        }
        
        $this->set('tricks', $tricks);
        $this->set('tricksKeys', $tricksKeys);
    }
     
    public function add(){
        if (!empty($this->request->data)){
            $data = $this->request->data;
            $r = $this->Trick->save($data);
        }
        
        $this->render(false);
    }
    
    public function del($id){
        $data = $this->Trick->delete($id);
        $this->render(false);
        return $data;
    }

    
   
    public function searchTricks(){
        $data = $this->request->data;
        
        $valSearch = $data['search'];
        //$varSearch = explode('');
        
        $conditions = array(
            'OR' => array(
                'TricksType.name LIKE ' => '%'.$valSearch.'%',
                'TricksTypesSpin.spin' => $valSearch, 
                'TricksType.multiple' => $valSearch
            )
        );
        debug($data);
        $tricks = $this->getListTricks(3, $conditions);
        
        $this->set('tricksTypes', $tricks);
    }
}
?>
